import { userInfoAPI } from '@/api/user'
export default {
  namespaced: true,
  state () {
    return {
      tokenObj: {},
      // 保存用户信息
      userInfo: {}
    }
  },
  mutations: {
    setToken (state, obj) {
      // 存到vuex里了
      state.tokenObj = obj
    },

    setUserInfo (state, obj) {
      state.userInfo = obj
    }
  },
  actions: {
    async reqUserInfo (ctx) {
      // 判断如果没有数据才发请求
      if (!ctx.state.userInfo.name) {
        // 发请求
        const res = await userInfoAPI()
        ctx.commit('setUserInfo', res.data)
      }
    }
  }
}
